// hyb_yl/set_jurisdiction/set_jurisdiction.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    contList: [{
      title: '用户签约消息提醒',
      key: 'qianynum',
      num: 0,
    }, {
      title: '提现审核结果通知',
      key: 'tixiannum',
      num: 0,
    }]
  },
  addNum: function (e) {
    var that = this
    /**
     *        submitOrder: msg.submitOrder, //就诊提醒
              OpenHalfcard: msg.OpenHalfcard, //用药提醒提醒
              Mobile: msg.Mobile, //问诊提醒（提醒患者，提醒医生通用）
              hexiao: msg.hexiao, //问诊状态提醒退款不接诊等等
              settled: msg.settled//接种提醒
     */
    var submitOrder = that.data.submitOrder
    var OpenHalfcard = that.data.OpenHalfcard
    var Mobile = that.data.Mobile
    var hexiao = that.data.hexiao
    var settled = that.data.settled
    var qainSuccess = that.data.qainSuccess
    console.log(submitOrder)
    wx.requestSubscribeMessage({
      tmplIds: [submitOrder, OpenHalfcard, Mobile],
      success: (res) => {
        console.log(res)
        //调用授权
      }
    })
  },
  addNum2: function (e) {
    var that = this
    var zid = that.data.zid
    var key = e.currentTarget.dataset.key;

    var qainSuccess = that.data.qainSuccess
    wx.requestSubscribeMessage({
      tmplIds: [qainSuccess],
      success: (res) => {
        console.log(res)
        //调用授权
        //调用授权
        let item = res[qainSuccess]
        if (item == "accept") {
          app.util.request({
            'url': 'entry/wxapp/zhuanjia.addtixingnum',
            data: {
              zid: zid,
              key: key
            },
            success: function (res) {
              console.log(res)
              that.getdocnum()
            }
          })
        }

      }
    })


  },
  addNum3: function (e) {
    var that = this
    var zid = that.data.zid
    var key = e.currentTarget.dataset.key;
    var tixianSuccess = that.data.tixianSuccess
    wx.requestSubscribeMessage({
      tmplIds: [tixianSuccess],
      success: (res) => {
        console.log(res)
        //调用授权
        let item = res[tixianSuccess]
        if (item == "accept") {
          app.util.request({
            'url': 'entry/wxapp/zhuanjia.addtixingnum',
            data: {
              zid: zid,
              key: key
            },
            success: function (res) {
              console.log(res)
              that.getdocnum()
            }
          })
        }

      }
    })


  },
  addNumtij:function(e){
    var that = this
    var jobnotice = that.data.jobnotice
    wx.requestSubscribeMessage({
      tmplIds: [jobnotice],
      success: (res) => {
        console.log(res)
        //调用授权
      }
    })
  },
  allAddnum: function (e) {
    var contList = this.data.contList
    for (var i = 0; i < contList.length; i++) {
      contList[i].num += 1
    }
    this.setData({
      contList,
    })
  },
  switch: function (e) {
    var switchValue = e.detail.value
    if (switchValue == true) {
      //打开
      this.dyBtn()
    } else {
      //关闭
    }
  },
  dyBtn: function () {
    console.log(123)
    var qiany = this.data.qiany
    wx.requestSubscribeMessage({
      tmplIds: [qiany],
      success: function (res) {
        console.log(res)
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    var zid = options.zid
    that.setData({
      zid: zid
    })
    that.getdocnum()
    //获取订阅消息id
    app.util.request({
      'url': 'entry/wxapp/index.techen',
      success: function (res) {
        console.log(res)
        var msg = res.data.wxapp_mb
        that.setData({
          submitOrder: msg.submitOrder, //就诊提醒
          OpenHalfcard: msg.OpenHalfcard, //用药提醒提醒
          Mobile: msg.Mobile, //问诊提醒（提醒患者，提醒医生通用）
          hexiao: msg.hexiao, //问诊状态提醒退款不接诊等等
          settled: msg.settled, //接种提醒,
          qainSuccess: msg.qainSuccess, //签约
          tixianSuccess: msg.tixianSuccess,
          jobnotice:msg.jobnotice
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  getdocnum() {
    var that = this
    var zid = that.data.zid
    console.log(zid)
    app.util.request({
      'url': 'entry/wxapp/zhuanjia.dockey',
      data: {
        zid: zid
      },
      success: function (res) {
        console.log(res)
        that.setData({
          qianynum: res.data.qianynum,
          tixiannum: res.data.tixiannum
        })
      }
    })
  }
})